<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>socket.io</title>
    <script src="http://localhost:8000/socket.io/socket.io.js"></script>
</head>
<body>
<h1>房间2</h1>
<input type="button" value="加入购物车" onclick="addCart()"><br>
</body>
</html>

<script type="text/javascript">
    //和服务器建立长连接
    var socket = io.connect('http://localhost:8000?roomid=2');
    //接收服务器返回的信息
    socket.on('addCart',function(data){
        console.log(data);
    });
    function addCart(){
        socket.emit('addCart','啊哈~');
    }

</script>